import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * This class is add course UI
 */
public class CourseUI  extends JPanel {
	/**
	 * title for the current window  
	 */
	private JLabel lbltitle = null;
	/**
	 * Label for id
	 */
	private JLabel lblID = null;
	/**
	 * Label for name
	 */
	private JLabel lblName = null;
	/**
	 * Label for hours number
	 */
	private JLabel lblNumOfHours = null;
	/**
	 * Label for teacher unit
	 */
	private JLabel lblTUnit = null;
	/**
	 * TextField for id
	 */
	private JTextField TextID = null;
	/**
	 * TextField for name
	 */
	private JTextField TextName = null;
	/**
	 * TextField for hours number
	 */
	private JTextField TextNumOfHours = null;
	/**
	 * TextField for teacher unit
	 */
	private JTextField TextTUnit = null;
	/**
	 * add course button
	 */
	private JButton btnAddCourse = null;
	/**
	 * back button
	 */
	public JButton btnBack = null;
	/**
	 * help button
	 */
	public JButton btnHelp = null;
	
	private String id;
	private String name;
	private String num;
	private String unit;

	
	
	public CourseUI () {
		super();
		initialize();
	}
	
	private void initialize() {
		/**
		 *  add course Implementation
		 */
		btnAddCourse = new JButton();
		btnAddCourse.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Course course = new Course(id,name,num,unit);
				SQL s = new SQL(course,9);
				s.accept();
				System.out.println("add course");
			}
		});
		btnAddCourse.setBounds(new Rectangle(116, 231, 200, 25));
		btnAddCourse.setText("Add Course");
		this.add(btnAddCourse,null);
		this.setVisible(true);
		
		lblID = new JLabel("Course ID:");
		lblID.setBounds(83, 60, 110, 14);
		this.add(lblID);	
			
		TextID = new JTextField();
		TextID.setBounds(new Rectangle(194, 60, 128, 25));
		TextID.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				id=TextID.getText();			
			}
		}
		);
		this.add(TextID,null);
		
		
		lblName = new JLabel("Course Name:");
		lblName.setBounds(83, 100, 110, 14);
		this.add(lblName);	
		
		TextName = new JTextField();
		TextName.setBounds(new Rectangle(194, 100, 128, 25));
		TextName.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				name = TextName.getText();
			}
		}
		);
		this.add(TextName,null);
		
		
		lblNumOfHours = new JLabel("Number of Hours:");
		lblNumOfHours.setBounds(83, 140, 110, 14);
		this.add(lblNumOfHours);
		
		TextNumOfHours = new JTextField();
		TextNumOfHours.setBounds(new Rectangle(194, 140, 128, 25));
		TextNumOfHours.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				num = TextNumOfHours.getText();	
					
			}
		}
		);
		this.add(TextNumOfHours,null);
		
		
		lblTUnit = new JLabel("Teaching Unit:");
		lblTUnit.setBounds(83, 180, 110, 14);
		this.add(lblTUnit);	
		
		TextTUnit = new JTextField();
		TextTUnit.setBounds(new Rectangle(194, 180, 128, 25));
		TextTUnit.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				unit=TextTUnit.getText();			
			}
		}
		);
		this.add(TextTUnit,null);
		

		lbltitle = new JLabel("Add Course");
		lbltitle.setBounds(156, 23, 110, 14);

		this.setSize(400, 321);
		this.setLayout(null);
		
		this.add(lbltitle);
	
		btnBack = new JButton("Back");
		btnBack.setBounds(177, 285, 86, 25);
		this.add(btnBack,null);
		this.setVisible(true);
		/**
		 *  help button Implementation
		 */
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Enter the Course details and then","click on 'Add Course' button");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);
		this.setVisible(true);
		
	}
}
